package Euler47;

import java.util.*;

import ReusableCode.PrimeFunctions;

public class DistinctPrimesFactors {
	public static void main(String[] args) {
		System.out.print("Working...");
		List<Integer> primes = PrimeFunctions.GetPrimes(200000);
		
		int num = 4;
		int count = 1;
		List<Integer> nums = new ArrayList<Integer>();
		
		while(nums.size()<num)
		{
			int numPrimes = factorizeHash(count, primes).size();
			
			if(numPrimes==num)
			{
				nums.add(count);
			}
			else if(nums.size()>0)
			{
				nums = new ArrayList<Integer>();
			}
			
			count++;
		}
		
		System.out.println(nums);
	}
	
	//Perform prime factorization on the given number.
	public static HashSet<Integer> factorizeHash(long num, List<Integer> primes)
	{
		HashSet<Integer> factors = new HashSet<Integer>();
		Iterator<Integer> iter = primes.iterator();
		
		int prime = 0;
		while(iter.hasNext() && prime < num)
		{
			long temp = num;
			prime = iter.next();
			
			if(temp%prime==0)
			{
				factors.add(prime);
			}
		}
		
		return factors;
	}
}
